#include "simpletcpserverdll.h"
#include "simpletcpserverdll_global.h"

static SimpleTcpServerDLL* SimpleTcpServerInstance = nullptr;

bool COM_ComServerInstanceExist(){
    if(SimpleTcpServerInstance == nullptr){
        if(SimpleTcpServerInstance == nullptr){
            return false;
        }
    }
    return true;
}

short COM_ComServerInstanceInit(){
    if(SimpleTcpServerInstance == nullptr){
        SimpleTcpServerInstance = new SimpleTcpServerDLL();
        return 1;
    }
    return 0;
}

short COM_ComServerInstanceRelease(){
    if(SimpleTcpServerInstance != nullptr){
        delete SimpleTcpServerInstance;
        return 1;
    }
    return 0;
}

void  COM_serverMainThreadLoopRun(short type){
    SimpleTcpServerInstance->SimpleServerMainThreadLoopRun(type);
}

short COM_ComServeradd(const int port, int& order){
    if(SimpleTcpServerInstance != nullptr){
        if(SimpleTcpServerInstance != nullptr){
            return SimpleTcpServerInstance->SimpleServeradd(port,order);
        }
    }
    return 0;
}

short COM_ComServerlisten(int order){
    if(SimpleTcpServerInstance != nullptr){
        if(SimpleTcpServerInstance != nullptr){
            return SimpleTcpServerInstance->SimpleServerlisten(order);
        }
    }
    return 0;
}


short COM_serverSendData(const int Order,const int SubOrder,QByteArray Data){
    if(SimpleTcpServerInstance != nullptr){
        if(SimpleTcpServerInstance != nullptr){
            return SimpleTcpServerInstance->SimpleTcpServerWriteData(Order,SubOrder,Data);
        }
    }
    return 0;
}
short COM_serverReadData(const int Order,const int SubOrder,QByteArray& Data){
    if(SimpleTcpServerInstance != nullptr){
        if(SimpleTcpServerInstance != nullptr){
            return SimpleTcpServerInstance->SimpleTcpServerReadData(Order,SubOrder,Data);
        }
    }
    return 0;
}


short COM_ComServerClientNumber(const int order,int& number){
    if(SimpleTcpServerInstance != nullptr){
        if(SimpleTcpServerInstance != nullptr){
            return SimpleTcpServerInstance->SimpleTcpServerConnetedClientNumber(order,number);
        }
    }
    return 0;
}

bool COM_getServerClientReadStatus(const int Order,const int subOrder){
    if(SimpleTcpServerInstance != nullptr){
        if(SimpleTcpServerInstance != nullptr){
            return SimpleTcpServerInstance->TcpServerRead2Read(Order,subOrder);
        }
    }
    return 0;
}
bool COM_getServerClientSendStatus(const int Order,const int subOrder){
    if(SimpleTcpServerInstance != nullptr){
        if(SimpleTcpServerInstance != nullptr){
            return SimpleTcpServerInstance->TcpServerSendBusy(Order,subOrder);
        }
    }
    return 0;
}

